/*! 
 * WeX5 v3 (http://www.justep.com) 
 * Copyright 2015 Justep, Inc.
 * Licensed under Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) 
 */
define(function(require) {
    var $ = require("jquery");
    var justep = require("$UI/system/lib/justep");
    var BizDesignComp = require("$UI/system/components/designerCommon/comp/bizDesignComp");
    require('css!./css/wxtemplate').load();
    
    
    function create(comp, clz) {
        var $domNode = $(comp.domNode);
        comp.domNode.style.position = "absolute";
        if (!comp.domNode.style.top) {
            comp.domNode.style.top = "10px";
            comp.domNode.style.left = "10px";
        }
        $domNode.addClass(clz).html('');
    }
   
    var templateSelect = function(propEditorMng) {
    	var templateMsgSelect = {
			url : "$UI/comp/wxtemplate/components/wxtemplate/designer/templateMsgChoose.w",
			buildTemplate : function(propConfig) {
				return "<div class='editor-container' style='position:relative;'>"
						+ "	<input "
						+ propEditorMng.buildCommonAttr(propConfig)
						+ "   readonly style='width:100%;padding-right:56px;' />"
						+ "   <span title='选择微信消息模板' class='dialog-btn icon-ios7-more' style='background:#efefef; display:block;width:22px;padding-left:5px;;z-index:100;position:absolute;top:1px;height:26px;line-height:26px;font-size:12px;right:1px'></span>"
						+ "</div>";
			}
		};
		propEditorMng.regEditorBuilder("templateMsgSelect", templateMsgSelect, "combo");
    };
	
    var wxtemplate = BizDesignComp.extend({

        // 初始化
        init: function(value, bindingContext) {
            create(this, 'x-wxtemplate');
            this.callParent(value, bindingContext);

        },
        // 构造函数
        constructor: function(options) {
            this.callParent(options);
        },

    });
    
    justep.Component.addOperations(wxtemplate, {
        'pushTemplateMsg': {
            label: '推送消息',
            argsDef: [
                {name:"prepayId",displayName:"预支付ID",editor:"jsExpressionEX"},
                {name:"formId",displayName:"表单ID",editor:"jsExpressionEX"},
                {name:"url",displayName:"消息跳转页面",editor:"pageUrlEditor"},
                {name:"params",displayName:"页面参数",editor:"pageParamSelector",placeHolder:"需在被打开页面定义页面参数"}
            ],
            method: function(args) {}
        }
    });

    var quickIdeEx = {
    	regPropEditor : function(propEditorMng) {
    		templateSelect(propEditorMng);
    	},
        "wxComp:wxtemplate": {
	        properties: [{
	            name: "label",
	            text: "显示名称"
	        },{
	        	name:"templateId",
	        	editor:"templateMsgSelect"
            },"emphasisKeyword",
            "toUser","one","two","three","four","five","six","seven","eight","nine","ten"
          ],
            events: [{
                name: "on:pushBefore",
                text: "推送前"
            }, {
                name: "on:pushSuccess",
                text: "推送成功"
            }, {
                name: "on:pushFail",
                text: "推送失败"
            }],
            operations: function() {
                return [{
                    groupName: "微信消息推送",
                    items: [{
                        name: 'pushTemplateMsg',
                        label: "推送消息",
                        argExtends: {}
                    }]
                }];
            },
            displayName: function(config) {
                return "微信服务消息";
            }
        }
    };

    return {
        'wxComp:wxtemplate': wxtemplate,
        quickIdeEx: quickIdeEx,
    };
});